;;; init-dev.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 gotpl
;;
;; Author: gotpl <631707329@qq.com>
;; Maintainer: gotpl <631707329@qq.com>
;; Created: 七月 28, 2023
;; Modified: 七月 28, 2023
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/gotpl/init-dev
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;  Description
;;
;;; Code:


;; Project management
;; (unload-feature 'transient t) ;; 卸载内置的，否则会警告
;; (unload-feature 'seq t)
;; (use-package msgu
;;   :defer t
;;   :ensure (:repo "https://github.com/jcs-elpa/msgu"))
;; (use-package seq
;;   :defer t)
;; (use-package transient
;;   :ensure (:repo "https://github.com/magit/transient.git" :files ("lisp/*") :tag "v0.4.2"))

(use-package lua-mode
  :ensure (:host github :repo "immerrr/lua-mode"))

(use-package magit
  :commands magit-status
  :ensure (:host github :repo "magit/magit" :tag "v3.3.0" :files (:defaults "lisp/*.el"))
  ;; :after transient
  )

(use-package treemacs-projectile
  ;; :after (treemacs projectile)
  :defer t
  )

(use-package projectile
  :bind (:map projectile-mode-map
              ("C-c p" . projectile-command-map))
  ;; .projectile 优先级高于projectile-register-project-type
  ;; :hook (after-init . (lambda ()
  ;;                       (require 'projectile)
                        
                        ;; (projectile-register-project-type 'cmake '("CmakeLists.txt")
                        ;;                                   :project-file "CmakeLists.txt"
                        ;;                                   :compile "if [ ! -d \\"./build\\" ]; then mkdir ./build && cd build && cmake .."
                        ;;                                   )
                        
                        ;; ))
  :hook (find-file . projectile-mode)
  :config
  (setq projectile-per-project-compilation-buffer t)
  (projectile-register-project-type 'xmake '("xmake.lua")
                                                          :project-file "xmake.lua"
                                                          :compile "xmake -vw"
                                                          :run "xmake run")
  (projectile-mode)
  (dolist (dir '("bazel-bin"
                 "bazel-out"
                 "bazel-testlogs"))
    (add-to-list 'projectile-globally-ignored-directories dir))
  :custom
  (projectile-use-git-grep t)
  (projectile-indexing-method 'alien)
  (projectile-kill-buffers-filter 'kill-only-files)
  ;; Ignore uninteresting files. It has no effect when using alien mode.
  (projectile-globally-ignored-files '("TAGS" "tags" ".DS_Store"))
  (projectile-globally-ignored-file-suffixes '(".elc" ".pyc" ".o" ".swp" ".so" ".a"))
  (projectile-ignored-projects `("~/"
                                 "/tmp/"
                                 "/private/tmp/"
                                 ,package-user-dir)))

(use-package treemacs
  ;; :init
  ;; (with-eval-after-load 'winum
  ;;   (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
  :init
  (require 'treemacs-projectile)
  :bind (("M-0"       . treemacs-select-window)
          ("C-x t 1"   . treemacs-delete-other-windows)
          ("C-x t t"   . treemacs)
          ("C-x t d"   . treemacs-select-directory)
          ("C-x t B"   . treemacs-bookmark)
          ("C-x t C-t" . treemacs-find-file)
          ("C-x t M-t" . treemacs-find-tag))
  :commands (treemacs treemacs-select-window)
  :config
  (add-hook 'treemacs-mode-hook '(lambda ()
                                   (display-line-numbers-mode -1)))
  (setq treemacs-collapse-dirs                   (if treemacs-python-executable 3 0)
        treemacs-deferred-git-apply-delay        0.5
        treemacs-directory-name-transformer      #'identity
        treemacs-display-in-side-window          t
        treemacs-eldoc-display                   'simple
        treemacs-file-event-delay                2000
        treemacs-file-extension-regex            treemacs-last-period-regex-value
        treemacs-file-follow-delay               0.2
        treemacs-file-name-transformer           #'identity
        treemacs-follow-after-init               t
        treemacs-expand-after-init               t
        treemacs-find-workspace-method           'find-for-file-or-pick-first
        treemacs-git-command-pipe                ""
        treemacs-goto-tag-strategy               'refetch-index
        treemacs-header-scroll-indicators        '(nil . "^^^^^^")
        treemacs-hide-dot-git-directory          t
        treemacs-indentation                     2
        treemacs-indentation-string              " "
        treemacs-is-never-other-window           nil
        treemacs-max-git-entries                 5000
        treemacs-missing-project-action          'ask
        treemacs-move-forward-on-expand          nil
        treemacs-no-png-images                   nil
        treemacs-no-delete-other-windows         t
        treemacs-project-follow-cleanup          nil
        treemacs-persist-file                    (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
        treemacs-position                        'left
        treemacs-read-string-input               'from-child-frame
        treemacs-recenter-distance               0.1
        treemacs-recenter-after-file-follow      nil
        treemacs-recenter-after-tag-follow       nil
        treemacs-recenter-after-project-jump     'always
        treemacs-recenter-after-project-expand   'on-distance
        treemacs-litter-directories              '("/node_modules" "/.venv" "/.cask")
        treemacs-project-follow-into-home        nil
        treemacs-show-cursor                     nil
        treemacs-show-hidden-files               t
        treemacs-silent-filewatch                nil
        treemacs-silent-refresh                  nil
        treemacs-sorting                         'alphabetic-asc
        treemacs-select-when-already-in-treemacs 'move-back
        treemacs-space-between-root-nodes        t
        treemacs-tag-follow-cleanup              t
        treemacs-tag-follow-delay                1.5
        treemacs-text-scale                      nil
        treemacs-user-mode-line-format           nil
        treemacs-user-header-line-format         nil
        treemacs-wide-toggle-width               70
        treemacs-width                           35
        treemacs-width-increment                 1
        treemacs-width-is-initially-locked       t
        treemacs-workspace-switch-cleanup        nil
        treemacs--project-follow-delay 0.1)

    ;; The default width and height of the icons is 22 pixels. If you are
    ;; using a Hi-DPI display, uncomment this to double the icon size.
    ;;(treemacs-resize-icons 44)

    (treemacs-follow-mode t)
    ;; 根据project自动切换，切换是打开treemacs 的情况下切换buffer或文件才会识别，放后台切换，打开treemacs不会刷新，需要保持treemacs打开再次切回buffer才会刷新
    (treemacs-project-follow-mode t)
    (treemacs-filewatch-mode t)
    (treemacs-fringe-indicator-mode 'always)
    (when treemacs-python-executable
      (treemacs-git-commit-diff-mode t))

    (pcase (cons (not (null (executable-find "git")))
                 (not (null treemacs-python-executable)))
      (`(t . t)
       (treemacs-git-mode 'deferred))
      (`(t . _)
       (treemacs-git-mode 'simple)))

    (treemacs-hide-gitignored-files-mode nil)
  )

;; treemacs-evil自动依赖evil 会把evil的depth设置为nil导致冲突
;; (straight-use-package '(evil :depth 1))
(use-package treemacs-evil
    
    :after (treemacs evil)
    )

(use-package treemacs-icons-dired
  :hook (dired-mode . treemacs-icons-dired-enable-once)
  )

(use-package treemacs-magit
  :after (treemacs magit)
  )

(use-package yasnippet

  :defer t
  :config

  (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  ;; (yas-global-mode 1)
  )

(use-package yasnippet-snippets
  ;; :after yasnippet ;; 本身就是after-load yasnippets之后加载
  :defer t
  :ensure (:repo "https://github.com/ipyffor/yasnippet-snippets"))

;; 移除模板中的注释头部
(defun remove-yas-header-comment (data)
  (interactive)
  (replace-regexp-in-string "# *-\\*- *mode: *snippet *-\\*-.*\\(?:\n\\|.\\)*# --\n*" "" data)
  )

(defun autoinsert-yas-expand()
  "Replace text in yasnippet template."
  (yas-expand-snippet (remove-yas-header-comment (buffer-string)) (point-min) (point-max)))


(defun get-line-to-top ()
  (print (count-lines (window-start) (point)))
  (print (window-start))
  (print (point))
  (- (count-lines (window-start) (point)) 1))

(defun goto-line-column-with-offset (ori-line ori-column ori-line-to-top)
  "Move cursor to a specific LINE and COLUMN, with an OFFSET from the window top."
  
  (goto-line ori-line)
  (beginning-of-line)
  (forward-char ori-column)
  ;; has bug
  ;; (let ((line-to-top (get-line-to-top)))
  ;;   (if (< ori-line-to-top line-to-top)
  ;;       (pixel-scroll-up (- line-to-top ori-line-to-top))
  ;;     (pixel-scroll-down (- ori-line-to-top line-to-top))))
  ;; 确定光标位置和希望的窗口顶端偏移
  )

;; 自动更新修改日期
(defun update-modified-date ()
  "Update the modified date in the file header."
  (interactive)
  (message "update head doc")
  (let ((ori-line (line-number-at-pos))
        (ori-column (current-column))
        (ori-line-to-top (get-line-to-top))) 
      (goto-char (point-min))
      (when (re-search-forward ".*Modified: *[0-9]\\{4\\}.*" nil t)
        (beginning-of-line)
        (replace-regexp "\\(.*Modified: *\\)\\(.*\\)" (format "\\1%s" (format-time-string "%Y-%m-%d %H:%M:%S")) ))
      (goto-line-column-with-offset ori-line ori-column ori-line-to-top)
    )
  )
;; (goto-line-column-with-offset 234 31 (get-line-to-top))
;; (window-at )
; (set-window-start nil )
;; 保存时自动更新
(add-hook 'before-save-hook 'update-modified-date)

(use-package autoinsert
  :ensure nil
  :after lsp-bridge
  :config
  (let ((template-dir (expand-file-name "snippets/file-templates/" user-emacs-directory)))
    (auto-insert-mode 1)

    (setq auto-insert-directory template-dir)
    (setq auto-insert-query nil) ;; If you don't want to be prompted before insertion
    (setq auto-insert-alist
          (append '(
                    (emacs-lisp-mode . ["emacs-lisp-mode/__package" autoinsert-yas-expand])
                    ;; (sh-mode . ["sh-mode/__" autoinsert-yas-expand])
                    )
                  auto-insert-alist))
    ;; (define-auto-insert "\\.py$" ["python-mode/__" autoinsert-yas-expand])
    ;; (define-auto-insert "\\.el$" ["emacs-lisp-mode/__package" autoinsert-yas-expand])
    ;; C/C++
    (define-auto-insert "\\.py$" ["python-mode/__" autoinsert-yas-expand])
    (define-auto-insert "\\.[Hh]$" ["c-mode/__h" autoinsert-yas-expand])
    (define-auto-insert "\\.sh$" ["sh-mode/__" autoinsert-yas-expand])
    (define-auto-insert "\\.hpp$" ["c-mode/__h" autoinsert-yas-expand])
    (define-auto-insert "\\.c$" ["c-mode/__c" autoinsert-yas-expand])
    (define-auto-insert "\\.cpp$" ["c-mode/__c" autoinsert-yas-expand])
    (define-auto-insert "main.cpp" ["c++-mode/__main.cpp" autoinsert-yas-expand])
    )
  )

(use-package evil-surround
  :after evil
  :config
  (global-evil-surround-mode))


;; lsp-bridge
(defvar lsp-brdige-loaded-p nil)
;; 使用advice-add 放到find-file之前执行,参数保持一致
(defun load-lsp-bridge! ()
  (when (not lsp-brdige-loaded-p)
    (require 'yasnippet-snippets)
    (yas-global-mode 1)
    (require 'lsp-bridge)
    (setq lsp-brdige-loaded-p t)
    (message "lsp-brige is loaded..."))
  
  )

;; (defvar lsp-bridge-on-p nil)
;; (defun turn-on-lsp-bridge! (FILENAME &optional WILDCARDS)
;;   (when (not lsp-bridge-on-p)
;;     (global-lsp-bridge-mode)
;;     (setq lsp-bridge-on-p t)))
;; (advice-add 'find-file :before #'load-lsp-bridge!)
;; (advice-add 'find-file :after #'turn-on-lsp-bridge!)

(use-package lsp-bridge
  :ensure '(lsp-bridge :type git :host github :repo "manateelazycat/lsp-bridge"
            :files (:defaults "*.el" "*.py" "acm" "core" "langserver" "multiserver" "resources")
            :build (:not compile))
  :init
  (setq lsp-bridge-enable-inlay-hint t
        lsp-bridge-enable-hover-diagnostic t)
  :hook (prog-mode . load-lsp-bridge!)
  :config
  ;; (setq lsp-bridge-enable-log t)
  (setq lsp-bridge-python-command emacs-python-path
        acm-quick-access-use-number-select t
        )
  (add-to-list 'lsp-bridge-formatting-indent-alist '(c++-ts-mode . c-basic-offset))
  (defun enable-lsp-bridge()
    (when-let* ((gcc-executable-p (gcc-is-executable))
                (arch (linux/get-arch))
                (lsp-dir (expand-file-name (format "lsp-bridge-server/gcc/%s" arch)user-emacs-directory)))
      (setq lsp-bridge-user-langserver-dir lsp-dir
                  lsp-bridge-user-multiserver-dir lsp-dir))
    (global-lsp-bridge-mode))
  (enable-lsp-bridge)
)

;; (use-package dashboard
;;   :ensure t
;;   :config
;;   (add-hook 'elpaca-after-init-hook #'dashboard-insert-startupify-lists)
;;   (add-hook 'elpaca-after-init-hook #'dashboard-initialize)
;;   (dashboard-setup-startup-hook))
;; (use-package lsp-bridge
;;   :ensure (lsp-bridge :type git :host github :repo "manateelazycat/lsp-bridge"
;;             :files (:defaults "*.el" "*.py" "acm" "core" "langserver" "multiserver" "resources")
;;             :build (:not compile)
;;                  )
;;   ;; :hook (find-file . load-lsp-bridge!)
;;   :custom
;;   ;; (lsp-bridge-enable-log t)
;;   ;; (acm-candidate-match-function 'orderless-flex)
;;   ;; (acm-backend-search-file-words-enable-fuzzy-match t)
;;   (lsp-bridge-enable-hover-diagnostic t)
;;   (lsp-bridge-enable-inlay-hint t)
;;   (acm-enable-quick-access t)
;;   ;; (lsp-bridge-signature-show-function 'lsp-bridge-signature-show-with-frame)
;;   ;; (lsp-bridge-signature-show-with-frame-position "point")
;;   (lsp-bridge-python-command emacs-python-path)
;;   ;; (acm-quick-access-use-number-select t) ;; 使用alt+数字，直接数字容易误操作
;;   :config
;;   ;; 谨慎更改该函数，补全不稳定极有可能是这里导致的
;;   ;; (setq lsp-bridge-get-project-path-by-filepath
;;   ;;       (lambda (filepath)
;;   ;;         (projectile-project-root)
;;   ;;         ))
;;   (add-to-list 'lsp-bridge-formatting-indent-alist '(c++-ts-mode . c-basic-offset))
;;   (defun toggle-lsp-bridge-log ()
;;       (interactive)
;;     (setq lsp-bridge-enable-log (not lsp-bridge-enable-log)))
;;   (global-lsp-bridge-mode)
;;   ;; (setq lsp-bridge-enable-log t)
;;   )

;; (use-package lsp-mode
;;   :ensure t
;;   :init
;;   ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
;;   (setq lsp-auto-configure t)
;;   ;; (setq lsp-prefer-capf t)
;;   (setq lsp-enable-snippet t)
;;   (setq lsp-keymap-prefix "C-l")
;;   ;; (setq lsp-enable-completion-at-point t)
;;   (setq lsp-completion-provider :none) ;; 禁止修改company后端, 否则先启动的company自定义后端会被覆盖

;;   (setq lsp-keep-workspace-alive nil)
;;   (setq lsp-enable-file-watchers nil)
;;   (setq lsp-enable-semantic-highlighting nil)
;;   (setq lsp-enable-symbol-highlighting nil)
;;   (setq lsp-headerline-breadcrumb-enable t
;;         lsp-modeline-diagnostics-enable t)
;;   :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
;;          ;; (prog-mode . lsp)
;;          ;; if you want which-key integration
;;          (lsp-mode . lsp-enable-which-key-integration)
;;          ((c++-ts-mode c-ts-mode python-ts-mode) . lsp-mode))
;;   :commands lsp
;;   :config
;;   )

;; (use-package lsp-pyright
;;   :ensure t
;;   :hook (python-mode . (lambda ()
;;                           (require 'lsp-pyright)
;;                           (lsp))))  ; or lsp-deferred

;; ;; 激活lsp-mode时u由lsp-mode启动
;; (use-package lsp-ui
;;   :ensure t
;;   :defer t
;;   :custom (lsp-ui-doc-position (quote at-point))
;;   (lsp-ui-doc-use-webkit t)
;;   (lsp-ui-sideline-enable t)
;;   (lsp-ui-doc-border "orange")
;;   (lsp-ui-doc-enable t)
;;   (lsp-ui-doc-position 'top)
;;   )

;; (use-package company
;;   :ensure t
;;   :defer t
;;   :hook (prog-mode . company-mode)
;;   :init ;; Don't convert to downcase.
;;   (setq-default company-dabbrev-downcase nil)
;;   :bind (("C-<tab>" . company-complete-common)
;;          ;;
;;          :map company-active-map        ;
;;          ("C-n" . company-select-next)
;;          ("C-p" . company-select-previous)
;;          ("C-s" . company-filter-candidates)
;;          ("<tab>" . company-complete-selection)
;;          ("TAB" . company-complete-selection)
;;          ("<return>" . company-complete-selection) ; 终端下无效
;;          ("RET" . company-complete-selection)      ; 终端下生效
;;          ;; :map company-filter-map                   ;
;;          ;; ("C-n" . company-select-next)
;;          ;; ("C-p" . company-select-previous)
;;          ;; ("<tab>" . company-complete-selection)
;;          ;; ("TAB" . company-complete-selection)
;;          ;; ("<return>" . company-complete-selection) ; 终端下无效
;;          ;; ("RET" . company-complete-selection)      ; 终端下生效
;;          :map company-search-map                   ;
;;          ("C-n" . company-select-next)
;;          ("C-p" . company-select-previous)
;;          ("<tab>" . company-complete-selection)
;;          ("TAB" . company-complete-selection)
;;          ("<return>" . company-complete-selection) ; 终端下无效
;;          ("RET" . company-complete-selection)      ; 终端下生效
;;          )
;;   :custom                               ;
;;   (company-minimum-prefix-length 1)
;;   (company-idle-delay 0.3)
;;   (company-show-quick-access 'right)
;;   (company-dabbrev-minimum-length 2)
;;   (company-transformers '(
;;                           company-sort-prefer-same-case-prefix
;;                           company-sort-by-occurrence))
;;   :config                               ;
;;   (setq company-backends '(
;;                            (
;;                             company-capf
;;                             company-yasnippet
;;                             company-files
;;                             )
;;                            (company-dabbrev-code company-keywords )
;;                            (company-dabbrev)
;;                            ))
;;   )
;; ;; ;; optionally
;; ;; if you are helm user
;; (use-package helm-lsp :ensure t :commands helm-lsp-workspace-symbol)
;; if you are ivy user
;; (use-package lsp-treemacs :commands lsp-treemacs-errors-list)

;; optionally if you want to use debugger
;; (use-package dap-mode)
;; (use-package dap-LANGUAGE) to load the dap adapter for your language

;; optional if you want which-key integration


;; (use-package eglot
;;   :ensure nil
;;   :hook (prog-mode . eglot-ensure)
;;   )

;; (unless (display-graphic-p)
;;   (use-package popon
;;     :after lsp-bridge)

;;   (use-package acm-terminal
;;     :after lsp-bridge
;;     :ensure (:repo "https://github.com/twlz0ne/acm-terminal" :depth 1)
;;     ))
;; ;;;;;;;;;;;;;;;;;;;;;;;

(use-package evil-nerd-commenter
  :bind ("M-;" . evilnc-comment-or-uncomment-lines)
  :config
  (evilnc-default-hotkeys)
  )

(use-package elisp-demos
  :after helpful
  :config
  (advice-add 'helpful-update :after #'elisp-demos-advice-helpful-update))

;; (require 'jsonrpc)
(use-package jsonrpc
  :defer t
  :ensure (:host github :branch "main" :repo "svaante/jsonrpc" :files ("*.el")))

(setq eval-expression-print-length nil)
(setq eval-expression-print-level nil)
(setq edebug-print-length nil
      edebug-print-level nil)


(use-package iedit
  :defer t
  ;; :init
  ;; (setq iedit-toggle-key-default nil)
  ;; :config
  )

(use-package evil-multiedit
  :after (evil)
  :bind ("C-;" . 'evil-multiedit-match-all)
  ;; :commands (evil-multiedit-default-keybinds)
  :config

  ;; (evil-multiedit-default-keybinds) ;;
  ;; (global-set-key (kbd "C-;") 'evil-multiedit-match-all)
  )

;; ;; (use-package highlight-indentation
;; ;;   :ensure (:host github :repo "antonj/Highlight-Indentation-for-Emacs")
;; ;;   :hook (prog-mode . highlight-indentation-mode)
;; ;;   :config
;; ;;   (setq highlight-indentation-blank-lines t)
;; ;;   )
;; ;; (use-package highlight-indent-guides
;; ;;   :ensure (:host github :repo "DarthFennec/highlight-indent-guides")
;; ;;   :hook (prog-mode . highlight-indent-guides-mode)
;; ;;   :config
;; ;;   (setq highlight-indent-guides-method 'character)
;; ;;   (setq highlight-indent-guides-responsive 'stack)
;; ;;   ;; (set-face-background 'highlight-indent-guides-odd-face "darkgray")
;; ;;   ;; (set-face-background 'highlight-indent-guides-even-face "dimgray")
;; ;;   ;; (set-face-foreground 'highlight-indent-guides-character-face "dimgray")
;; ;; )
;; ;; --- language ---
;; (use-package lua-mode

;;   )

(use-package better-jumper
  :ensure (:host github :repo "gilbertw1/better-jumper")
  :after evil
  :config
  (better-jumper-mode +1)
  (setq better-jumper-use-evil-jump-advice t)
  (with-eval-after-load 'evil-maps
  (define-key evil-motion-state-map (kbd "C-o") 'better-jumper-jump-backward)
  (define-key evil-motion-state-map (kbd "C-i") 'better-jumper-jump-forward)))
;; 语法高亮

(use-package treesit-auto
  :ensure (:host github :repo "renzmann/treesit-auto")
  :init
  (setq treesit-language-source-alist
      '((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
        (c . ("https://github.com/tree-sitter/tree-sitter-c"))
        (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp" "v0.22.0")) ;; 新版本有bug
        (css . ("https://github.com/tree-sitter/tree-sitter-css"))
        (cmake . ("https://github.com/uyha/tree-sitter-cmake"))
        (csharp     . ("https://github.com/tree-sitter/tree-sitter-c-sharp.git"))
        (dockerfile . ("https://github.com/camdencheek/tree-sitter-dockerfile"))
        (elisp . ("https://github.com/Wilfred/tree-sitter-elisp"))
        (go . ("https://github.com/tree-sitter/tree-sitter-go"))
        (gomod      . ("https://github.com/camdencheek/tree-sitter-go-mod.git"))
        (html . ("https://github.com/tree-sitter/tree-sitter-html"))
        (java       . ("https://github.com/tree-sitter/tree-sitter-java.git"))
        (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
        (json . ("https://github.com/tree-sitter/tree-sitter-json"))
        (lua . ("https://github.com/Azganoth/tree-sitter-lua"))
        (make . ("https://github.com/alemuller/tree-sitter-make"))
        (markdown . ("https://github.com/MDeiml/tree-sitter-markdown" nil "tree-sitter-markdown/src"))
        (ocaml . ("https://github.com/tree-sitter/tree-sitter-ocaml" nil "ocaml/src"))
        (org . ("https://github.com/milisims/tree-sitter-org"))
        (python . ("https://github.com/tree-sitter/tree-sitter-python"))
        (php . ("https://github.com/tree-sitter/tree-sitter-php"))
        (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" nil "typescript/src"))
        (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" nil "tsx/src"))
        (ruby . ("https://github.com/tree-sitter/tree-sitter-ruby"))
        (rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
        (sql . ("https://github.com/m-novikov/tree-sitter-sql"))
        (vue . ("https://github.com/merico-dev/tree-sitter-vue"))
        (yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))
        (toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
        (zig . ("https://github.com/GrayJack/tree-sitter-zig"))))
  ;; :after lsp-bridge
  :config
  (setq treesit-auto-install 'prompt)
  (setq treesit-font-lock-level 4)
  (global-treesit-auto-mode)
  (treesit-auto-add-to-auto-mode-alist 'all)

  (add-hook 'markdown-mode-hook #'(lambda () (treesit-parser-create 'markdown)))
  ;; (add-hook 'zig-mode-hook #'(lambda () (treesit-parser-create 'zig)))
  (add-hook 'emacs-lisp-mode-hook #'(lambda () (treesit-parser-create 'elisp)))
  ;; (add-hook 'ielm-mode-hook #'(lambda () (treesit-parser-create 'elisp)))
  (add-hook 'json-mode-hook #'(lambda () (treesit-parser-create 'json)))
  ;; (add-hook 'go-mode-hook #'(lambda () (treesit-parser-create 'go)))
  ;; (add-hook 'java-mode-hook #'(lambda () (treesit-parser-create 'java)))
  ;; (add-hook 'java-ts-mode-hook #'(lambda () (treesit-parser-create 'java)))
  ;; (add-hook 'php-mode-hook #'(lambda () (treesit-parser-create 'php)))
  ;; (add-hook 'php-ts-mode-hook #'(lambda () (treesit-parser-create 'php)))
  ;; (add-hook 'c++-ts-mode-hook #'(lambda () (treesit-parser-create 'cpp)))

  (add-hook 'web-mode-hook #'(lambda ()
                              (let ((file-name (buffer-file-name)))
                                (when file-name
                                  (treesit-parser-create
                                    (pcase (file-name-extension file-name)
                                      ("vue" 'vue)
                                      ("html" 'html)
                                      ("php" 'php))))
                                )))
  )

;; (use-package origami
;;   :ensure (:repo "https://github.com/ipyffor/origami.el.git")
;;   :config
;;   (global-origami-mode t))

;; format code
(use-package format-all
  :commands (format-all-region-or-buffer)
  )


;; (use-package realgud
;;   :after (lsp-bridge projectile)
;;   :config
;;   (defun projectile-realgud-gdb ()
;;     "Invoke `realgud-gdb' in the project's root."
;;     (interactive)
;;     (projectile-with-default-dir (projectile-acquire-root)
;;       (call-interactively 'realgud:gdb)))
;;   )

(use-package dape
  :ensure (:host github :repo "svaante/dape")
  :after lsp-bridge
  :bind (([f5] . dape)
         ([f9] . dape-breakpoint-toggle)
         ([f10] . dape-next)
         ([f11] . dape-step-in)
         ([S-f11] . dape-step-out))
  :config
  ;; (setq dape-debug t)
  (add-hook 'dape-start-hook (lambda () (save-some-buffers t t)))
  (setq dape-cwd-fn 'projectile-project-root)
  )
;; inhancement help builtin.
(use-package helpful
  :ensure (:host github :repo "Wilfred/helpful"))

(use-package origami
  :ensure t
  :hook (prog-mode . origami-mode))

;; lang
(add-to-list 'load-path (file-name-as-directory (expand-file-name "lisp/lang" user-emacs-directory)))
(require 'init-python)
(require 'init-elisp)
(require 'init-c++)
(provide 'init-dev)
;;; init-dev.el ends here
